package com.cw.lang.redis.service.impl;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;

import com.cw.lang.redis.service.RedisForSetService;

import lombok.Getter;
import lombok.Setter;

/**
 * redisTemplate.opsForSet()操作set
 *
 * @author chenw
 * @version $$Id: RedisForSetServiceImpl.java, v 0.1 2018/11/19 3:33 PM chenw Exp $$
 */
@Getter
@Setter
public class RedisForSetServiceImpl<K extends Serializable, V extends Serializable> extends AbstractRedisService<K, V>
    implements RedisForSetService<K, V> {

    @Override
    public Long add(K key, V... values) {
        return getRedisTemplate(key).opsForSet()
            .add(key, values);
    }

    @Override
    public Long remove(K key, Object... values) {
        return getRedisTemplate(key).opsForSet()
            .remove(key, values);
    }

    @Override
    public V pop(K key) {
        return getRedisTemplate(key).opsForSet()
            .pop(key);
    }

    @Override
    public List<V> pop(K key, long count) {
        return getRedisTemplate(key).opsForSet()
            .pop(key, count);
    }

    @Override
    public Boolean move(K key, V value, K destKey) {
        return getRedisTemplate(key).opsForSet()
            .move(key, value, destKey);
    }

    @Override
    public Long size(K key) {
        return getRedisTemplate(key).opsForSet()
            .size(key);
    }

    @Override
    public Boolean isMember(K key, Object o) {
        return getRedisTemplate(key).opsForSet()
            .isMember(key, o);
    }

    @Override
    public Set<V> intersect(K key, K otherKey) {
        return getRedisTemplate(key).opsForSet()
            .intersect(key, otherKey);
    }

    @Override
    public Set<V> intersect(K key, Collection<K> otherKeys) {
        return getRedisTemplate(key).opsForSet()
            .intersect(key, otherKeys);
    }

    @Override
    public Long intersectAndStore(K key, K otherKey, K destKey) {
        return getRedisTemplate(key).opsForSet()
            .intersectAndStore(key, otherKey, destKey);
    }

    @Override
    public Long intersectAndStore(K key, Collection<K> otherKeys, K destKey) {
        return getRedisTemplate(key).opsForSet()
            .intersectAndStore(key, otherKeys, destKey);
    }

    @Override
    public Set<V> union(K key, K otherKey) {
        return getRedisTemplate(key).opsForSet()
            .union(key, otherKey);
    }

    @Override
    public Set<V> union(K key, Collection<K> otherKeys) {
        return getRedisTemplate(key).opsForSet()
            .union(key, otherKeys);
    }

    @Override
    public Long unionAndStore(K key, K otherKey, K destKey) {
        return getRedisTemplate(key).opsForSet()
            .unionAndStore(key, otherKey, destKey);
    }

    @Override
    public Long unionAndStore(K key, Collection<K> otherKeys, K destKey) {
        return getRedisTemplate(key).opsForSet()
            .unionAndStore(key, otherKeys, destKey);
    }

    @Override
    public Set<V> difference(K key, K otherKey) {
        return getRedisTemplate(key).opsForSet()
            .difference(key, otherKey);
    }

    @Override
    public Set<V> difference(K key, Collection<K> otherKeys) {
        return getRedisTemplate(key).opsForSet()
            .difference(key, otherKeys);
    }

    @Override
    public Long differenceAndStore(K key, K otherKey, K destKey) {
        return getRedisTemplate(key).opsForSet()
            .differenceAndStore(key, otherKey, destKey);
    }

    @Override
    public Long differenceAndStore(K key, Collection<K> otherKeys, K destKey) {
        return getRedisTemplate(key).opsForSet()
            .differenceAndStore(key, otherKeys, destKey);
    }

    @Override
    public Set<V> members(K key) {
        return getRedisTemplate(key).opsForSet()
            .members(key);
    }

    @Override
    public V randomMember(K key) {
        return getRedisTemplate(key).opsForSet()
            .randomMember(key);
    }

    @Override
    public Set<V> distinctRandomMembers(K key, long count) {
        return getRedisTemplate(key).opsForSet()
            .distinctRandomMembers(key, count);
    }

    @Override
    public List<V> randomMembers(K key, long count) {
        return getRedisTemplate(key).opsForSet()
            .randomMembers(key, count);
    }

    @Override
    public Cursor<V> scan(K key, ScanOptions options) {
        return getRedisTemplate(key).opsForSet()
            .scan(key, options);
    }
}

